<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>14 浅比较</title>
</head>

<body>
  <script>
    // 默认配置项
    let defaults = {
      url: "",
      method: "GET",
      headers: {
        'Content-Type': 'application/json'
      },
      params: null,
      cache: {}
    }

    // 用户自定义配置项
    let options = {
      url: "http://jsonplaceholder.com",
      headers: {
        'x-token': 'xxxx',
      },
      params: {
        id: 100,
        from: "weixin"
      },
      cache: 999
    }

    let result = Object.assign(defaults, options)

    console.log(JSON.stringify(result, null, 2))
  </script>
</body>

</html>